package com.whz.parameterized;

import com.google.common.collect.Lists;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @Author: sinosoft
 * @Description:
 * @Date: Create in 16:40 2021/5/11
 * @Modified By:
 */
public class Chooser<T> {
    private final List<T> choiceList;
    public Chooser(Collection<? extends T> choices) {
        choiceList = Lists.newArrayList(choices);
    }
    public T choose() {
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        return choiceList.get(rnd.nextInt(choiceList.size()));
    }
}
